<?php

namespace Ue\tools;
class Aes
{
    private $key;
    private $iv;

    public function __construct($key, $iv = 'a46ef9a97bb04ea6')
    {
        $this->key = $key;
        $this->iv = $iv;
    }

    public function encrypt($text)
    {
        $cipherText = openssl_encrypt($text, 'aes-256-cbc', $this->key, OPENSSL_RAW_DATA, $this->iv);
        return bin2hex($cipherText);
    }

    public function decrypt($text)
    {
        $cipherText = hex2bin($text);
        return openssl_decrypt($cipherText, 'aes-256-cbc', $this->key, OPENSSL_RAW_DATA, $this->iv);
    }
}
